var $appTools={
  //表单验证
  'validator':function(selector){;
    var form = $(selector);
    var input = form.find(".form-validator");
    input.removeClass("am-field-error");
    for(var i=0;i<input.length;i++){
      var self = input.eq(i);
      var valData = self.attr("val-data");
      var msg = self.attr("val-data-msg");
      var value = self.val();
      if(valData.indexOf("require")!=-1){
        if($appTools.isEmpty(value)){
          self.addClass("am-field-error");
          self.focus();
          toastr.error(msg);
          return false;
        }
      }
    };
    return true;
  },
  //判断数据是否为空
  'isEmpty':function(data){
    if(data==""||data==null){
      return true;
    }else{
      return false;
    }
  },
  'getUrlParam':function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if(r != null) return decodeURI(r[2]);
    return null; //返回参数值
  },
  //添加cookie
  'setCookie':function(name, value) {
    //var Days = 1;
    var exp = new Date();
    exp.setTime(exp.getTime() +   60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();
  },
  //读取cookie
  'getCookie':function(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
      return unescape(arr[2]);
    else
      return null;
  },
  //删除cookies
  'delCookie':function(name) {
      var exp = new Date();
      exp.setTime(exp.getTime() - 1);
      var cval = $appTools.getCookie(name);
      if (cval != null)
        document.cookie = name + "=" + cval + ";path=/;expires=" + exp.toGMTString();
  },
  'confirm':function(text,yes,no){
   var html = '<div class="am-modal am-modal-alert" tabindex="-1" style="z-index:99999" id="my-confirm">'
              +'<div class="am-modal-dialog">'
              +'<div class="am-modal-hd">系统提示</div>'
              +'<div class="am-modal-bd" id="my-alert-text">'
              +''
              +' </div>'
              +'<div class="am-modal-footer">'
              +'<span class="am-modal-btn" id="my-confirm-cancel">取消</span>'
              +'<span class="am-modal-btn" id="my-confirm-yes" >确定</span>'
              +'</div>'
              +'</div>'
              +'</div>';

     var $modal = $('#my-confirm');
     //console.log($modal.length);
     if($modal.length==0){
       $("body").append(html);
       $modal = $('#my-confirm');
     }
     $("#my-alert-text").text(text);
     $modal.modal('open');
     $("#my-confirm-cancel").unbind().click(function(){
         no();
     });
     $("#my-confirm-yes").unbind().click(function(){
       yes();
     })
 },
};
